﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GFMS.MODEL;
using KPIS.GERP.GFMS.IDAL;

namespace KPIS.GERP.GFMS.DAL
{
    public class D_BGM_StrategyDataList : IDAL_BGM_StrategyDataList
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        ConvertNullable cn = new ConvertNullable();

        public M_BGM_StrategyDataList GetInfo(int seq)
        {
            string strSQL;
            DataRowCollection drc = null;
            M_BGM_StrategyDataList info = new M_BGM_StrategyDataList();

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);

                dbManager.AddParameters(0, "@seq", seq);

                strSQL = "SELECT list.bgm_strat_list_seq, list.bgm_strat_list_code"
                    + ", list.bgm_strat_list_name, list.bgm_strat_list_descr"
                    + ", list.bgm_strat_type_seq"

                    + ", strmap.record_status"
                    + " FROM bgm_strategy_data_list list"
                    + " LEFT JOIN bgm_strategy_data_mapping data ON list.bgm_strat_list_seq = data.bgm_strat_list_seq"
                    + " LEFT JOIN bgm_strategy_data_mapping updata ON data.upper_bgm_strat_data_map_seq = updata.bgm_strat_data_map_seq"
                    + " LEFT JOIN bgm_strategy_data_list uplist ON updata.bgm_strat_list_seq = uplist.bgm_strat_list_seq"
                    + " LEFT JOIN bgm_mas_strategy_type type ON list.bgm_strat_type_seq = type.bgm_strat_type_seq"
                    + " WHERE list.bgm_strat_list_seq = @seq";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    info.bgm_strat_list_seq = Convert.ToInt32(drc[0]["bgm_strat_list_seq"]);
                    info.bgm_strat_list_code = drc[0]["bgm_strat_list_code"].ToString();
                    info.bgm_strat_list_name = drc[0]["bgm_strat_list_name"].ToString();
                    //info.upper_bgm_strat_data_map_seq = drc[0]["bgm_strat_list_name"].ToString();
                    //info.bgm_strat_type_seq = cn.ConvertNullInt(drc[0]["bgm_strat_type_seq"]);
                    //info.m_bgm_strategydatalist.bgm_strat_list_name = drc[0]["bgm_strat_list_name"].ToString();
                    //info.m_bgm_strategydatalist.m_bgm_strategytype.bgm_strat_type_name = drc[0]["bgm_strat_type_name"].ToString();

                    info.record_status = drc[0]["record_status"].ToString();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return info;
        }
    }
}
